from marshmallow import fields

from gis.common.django_ext.forms import PaginationSchema, BaseSchema, EnumField
from itpay.core.user.const import UserLevel


class LoginSchema(BaseSchema):
    user_name = fields.String(required=True)
    password = fields.String(required=True)


class AgencyListSchema(PaginationSchema):
    id = fields.Integer()
    agency_name = fields.String()
    enable = fields.Boolean()
    mch_id = fields.Integer()
    use_vcode = fields.Boolean()
    working = fields.Boolean()
    use_white_ips = fields.Boolean()
    level = fields.Integer()
    user_level = fields.Integer()


class AddAgencySchema(BaseSchema):
    user_name = fields.String(required=True)
    enable = fields.Boolean(required=True)
    use_vcode = fields.Boolean()
    mch_ids = fields.List(fields.Integer(), allow_none=True)
    warning_amount = fields.Integer()
    remark = fields.String(allow_none=True)
    white_ips = fields.List(fields.String(), allow_none=True)
    avatar = fields.String(allow_none=True)


class UpdateAgencySchema(BaseSchema):
    enable = fields.Boolean(required=True)
    use_vcode = fields.Boolean(allow_none=True)
    mch_ids = fields.List(fields.Integer(), allow_none=True)
    warning_amount = fields.Integer(allow_none=True)
    remark = fields.String(allow_none=True)
    white_ips = fields.List(fields.String(), allow_none=True)
    avatar = fields.String(allow_none=True)
    nickname = fields.String(allow_none=True)


class UpdateAgencyInfoSchema(BaseSchema):
    nickname = fields.String(allow_none=True)
    prologue = fields.String(allow_none=True)
    avatar = fields.String(allow_none=True)
    im_leaving_time = fields.Integer()
    auto_show_level = EnumField(enum=UserLevel, allow_none=True)


class ResetMyPasswordSchema(BaseSchema):
    old_password = fields.String(required=True)
    password = fields.String(required=True)


class ComplainAgencySchema(PaginationSchema):
    mch_id = fields.Integer()
    user_id = fields.Integer()
    agency_id = fields.Integer()
    agency_name = fields.String()
    complaint_content = fields.String()
    complaint_types = fields.Integer()
    created_at_begin = fields.DateTime()
    created_at_end = fields.DateTime()
    updated_at_begin = fields.DateTime()
    updated_at_end = fields.DateTime()
    has_done = fields.Boolean()


class AgencyStatsReportSchema(PaginationSchema):
    agency_ids = fields.String()
    mch_ids = fields.String()
    parent_name = fields.String()
    time_range = fields.String()
    sort_by = fields.String()
    user_type = fields.String()
